package views;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA.
 * User: Артемка
 * Date: 15.12.13
 * Time: 11:05
 * To change this template use File | Settings | File Templates.
 */
public class GroupView extends JFrame {
    private JButton addButton, cancelButton;
    private JTextField tf1, tf2;
    private JTextArea ta1, ta2;
    private JPanel panel;
    private GridBagLayout layout;

    public GroupView() {


        layout = new GridBagLayout();
        panel = new JPanel(layout);

        addButton = new JButton("Добавить");
        cancelButton = new JButton("Отмена");

        tf1 = new JTextField("", 20);
        tf2 = new JTextField("", 20);


        ta1 = new JTextArea("Группа: ");
        ta2 = new JTextArea("Факультет: ");


        panel.add(ta1, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(tf1, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(ta2, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(tf2, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));

        panel.add(addButton, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(20, 20, 5, 5), 0, 0));
        panel.add(cancelButton, new GridBagConstraints(1, 2, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(20, 0, 5, 5), 20, 0));


        //  panel.add(jb4, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.CENTER,
        //      GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));

        //cancelButton.setLayout();
        add(panel);

    }
    public void addListenerForAdd(ActionListener listener) {
        addButton.addActionListener(listener);
    }

    public void addListenerForCancel(ActionListener listener) {
        cancelButton.addActionListener(listener);
    }

    public String getNameGroup(){
        return tf1.getText();
    }
    public String getFaculty(){
        return tf2.getText();
    }

    public void errorMessage(String s){
        JOptionPane.showMessageDialog(this, s, "Ошибка!", JOptionPane.WARNING_MESSAGE);
    }

    public void addMessage(String s){
        JOptionPane.showMessageDialog(this, s,"Поздравляем!", JOptionPane.INFORMATION_MESSAGE);
    }
}
